// src/components/c-service/service-detail/return/index.js
const App = getApp()
import {
  ServiceModel
} from '../../../../models/service'
const modelService = new ServiceModel()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    scanCode: String,
    serviceInfo:Object
  },

  /**
   * 组件的初始数据
   */
  data: {
    sendExpressName: '',
    sendExpressCode:''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //输入物流公司
    sendExpressName: function (e) {
      this.setData({
        sendExpressName:e.detail.value
      })
    },
    //输入单号
    sendExpressCode: function (e) {
      this.setData({
        sendExpressCode:e.detail.value
      })
    },
    //扫码
    tapToScan: function (event) {
      var that = this
      wx.scanCode({
        onlyFromCamera: true,
        scanType: ['barCode'],
        success: function (res) {
          that.setData({
            sendExpressCode: res.result
          })
        }
      })
    },

    //复制地址
    copyTBL: function () {
      var self = this;
      wx.setClipboardData({
        data: self.properties.serviceInfo.returnAddress+self.properties.serviceInfo.returnName+self.properties.serviceInfo.returnPhone,
        success: function (res) {
          // App.WxService.showToast({ title: '复制成功', icon: 'none' })
        }
      })
    },

    //提交物流信息
    submit: function () {
      const self = this;
      //非空判断
      if (!self.data.sendExpressName) {
        App.WxService.showToast({ title: '请输入物流公司', icon: 'none' });
        return;
      }
      if (!self.data.sendExpressCode) {
        App.WxService.showToast({ title: '请输入快递单号', icon: 'none' });
        return;
      }
      const params = {
        returnId: self.properties.serviceInfo.id,
        expressName: self.data.sendExpressName,
        expressCode:self.data.sendExpressCode
      }

      modelService.sendBack(params).then(res => {
        App.WxService.showToast({ title: '寄回成功', icon: 'none' })
        wx.navigateTo({url:'/pages/account/service/detail/index?returnId='+self.properties.serviceInfo.id})
      }).catch();
    }
  }
})
